package com.vlong.town.controller.server.hotel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.vlong.town.controller.base.BaseController;
import com.vlong.town.entity.hotel.HotelInfo;
import com.vlong.town.service.hotel.HotelInfoService;
/**
 * 酒店Rest接口Controller
 * @author Assassin
 */
@RequestMapping("/rest/hotel")
@RestController
public class HotelInfoRestController extends BaseController{
		
		@Autowired
		private  HotelInfoService hotelInfoService;
	
	   /**
	     * 查询酒店
	     * @param pageNo 当前页码
	     * @param pageSize 每页显示记录数
	     * @return List<HotelInfo>
	     */
	    @GetMapping("/list/{pageNo}/{pageSize}")
	    public List<HotelInfo> list(
	            @PathVariable(required=true, value="pageNo") Integer pageNo,
	            @PathVariable(required=true, value="pageSize") Integer pageSize) {
	        PageHelper.startPage(getPageNo(pageNo), getPageSize(pageSize));
	        PageHelper.orderBy("update_time DESC");
	        List<HotelInfo> hotelInfoList = this.hotelInfoService.queryList(null,null, null, null,null);
	        return hotelInfoList;
	    }
	    
	    
	    /**
	     * 小程序
	     * 查询酒店
	     * @param pageNo 当前页码
	     * @param pageSize 每页显示记录数
	     * @return List<HotelInfo>
	     */
	    @GetMapping("/listXcx/{type}")
	    public List<HotelInfo> listXcx(
	    		@PathVariable(required=true, value="type") Integer type
	    		) {
	        List<HotelInfo> hotelInfoList = this.hotelInfoService.queryList(null,type,null, null,null);
	        for (HotelInfo hotelInfo : hotelInfoList) {
	        	Long createTime = hotelInfo.getCreateTime();
	        	SimpleDateFormat  sdf=new  SimpleDateFormat("yyyy-MM-dd");
	        	Date date = new  Date(createTime);
	        	String format = sdf.format(date);
	        	hotelInfo.setCreateDate(format);
			}	
	        return hotelInfoList;
	    }
	    
	    /**
	     * 查询酒店详情
	     * @param id 酒店id
	     * @return HotelInfo
	     */
	    @GetMapping("/detail/{id}")
	    public HotelInfo detail(@PathVariable(required=true, value="id") Long id) {
	    	return hotelInfoService.queryById(id);
	    }
}
